using System.Threading.Tasks;
using HengTong.ViewModel.Common.SysSealVms;
using Microsoft.AspNetCore.Mvc;
using TiaoTaoHelper.Wtm.Attributes;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Mvc;
using WalkingTec.Mvvm.Mvc.Binders;

namespace HengTong.Areas.Common.Controllers;

[AuthorizeJwtWithCookie]
public partial class SysSealController
{
    [ActionDescription("Sys.Create")]
    [HttpPost("Add")]
    [StringNeedLTGT]
    [PreventDuplicateSubmit]
    public async Task<IActionResult> Add(SysSealVm vm)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState.GetErrorJson());
        }
        else
        {
            await vm.DoAddAsync();
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState.GetErrorJson());
            }
            else
            {
                return Ok(vm.Entity);
            }
        }
    }

    [ActionDescription("Sys.Edit")]
    [HttpPut("Edit")]
    [StringNeedLTGT]
    public async Task<IActionResult> Edit(SysSealVm vm)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState.GetErrorJson());
        }
        else
        {
            await vm.DoEditAsync(false);
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState.GetErrorJson());
            }
            else
            {
                return Ok(vm.Entity);
            }
        }
    }
}